package ssf.app.service;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.dao.EmptyResultDataAccessException;

import ssf.core.common.PagingList;

public class UserService extends BaseService {
	// 按用户名查找用户信息(登录)
	private static final String SQL_GET_USER_BY_USERNAME = "select * from pioneer_user where userName=?";

	/**
	 * 按用户名查找用户信息(登录)
	 */
	public Map getUserByUserName(String userName) {
		try {
			return jt.queryForMap(SQL_GET_USER_BY_USERNAME,
					new Object[] { userName });
		} catch (EmptyResultDataAccessException e) {// 如果用户不存在，则要抛出该异常
			return null;
		}
	}

	// 获取全部用户信息
	private static final String SQL_GET_ALL_USERS = "select * from pioneer_user";

	/**
	 * 获取全部用户信息
	 */
	public PagingList getAllUsers(HttpServletRequest request) {
		return getPagingList(SQL_GET_ALL_USERS, request);
	}

	// 根据ID查找用户信息
	private static final String SQL_GET_USER_BY_USERID = "select * from pioneer_user where userId=?";

	/**
	 * 根据ID查找用户信息
	 */
	public Map getUserByUserId(String userId) {
		return jt.queryForMap(SQL_GET_USER_BY_USERID, new Object[] { userId });
	}
}
